home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 April / april_2001.iso / intercd / root / ^Palm / Games / eCross / src / Title.java < prev    next >
Encoding:
Java Source  |  2000-07-28  |  2.0 KB  |  75 lines

  1. /*
  2.  * Title.java - Displays a Palm-like title
  3.  * eCross is Copyright (C) 2000 Romain Guy
  4.  * guy.romain@bigfoot.com
  5.  * www.jext.org
  6.  *
  7.  * This program is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU General Public License
  9.  * as published by the Free Software Foundation; either version 2
  10.  * of the License, or any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  */
  21.  
  22. import waba.fx.*;
  23. import waba.ui.*;
  24.  
  25. /**
  26.  * A control that displays an application's title.
  27.  * @version 1.0
  28.  * @author Wabasoft <www.wabasoft.com> and Romain Guy <guy.romain@bigfoot.com>
  29.  */
  30.  
  31. public class Title extends Bounded
  32. {
  33.   // title
  34.   private Font font;
  35.   private String name;
  36.  
  37.   /**
  38.    * Creates a new title.
  39.    * @param name The title label
  40.    */
  41.  
  42.   public Title(String name)
  43.   {
  44.     this.name = name;
  45.     this.font = new Font("Helvetica", Font.BOLD, 12);
  46.   }
  47.  
  48.   public int getBoxWidth(Control c)
  49.   {
  50.     return (c.getFontMetrics(font).getTextWidth(name) + 8);
  51.   }
  52.  
  53.   public void paint(Control c, Graphics g)
  54.   {
  55.     // draw line across
  56.     g.setColor(0, 0, 0);
  57.     int y = this.height - 1;
  58.     g.drawLine(0, y, this.width, y);
  59.     y--;
  60.     g.drawLine(0, y, this.width, y);
  61.  
  62.     // draw title
  63.     FontMetrics fm = c.getFontMetrics(font);
  64.     int boxWidth = fm.getTextWidth(name) + 8;
  65.     g.fillRect(0, 0, boxWidth, y);
  66.     g.setColor(255, 255, 255);
  67.     g.drawLine(0, 0, 0, 0);
  68.     g.drawLine(boxWidth - 1, 0, boxWidth - 1, 0);
  69.     g.setFont(font);
  70.     g.drawText(name, 4, 2);
  71.   }
  72. }
  73.  
  74. // End of Title.java
  75.